import { move, isWin } from './play.js';
import { showUi } from './ui.js';

showUi();

//完成整个游戏
var over = false;


window.onkeydown = function (e) {
    var result = false;
    if (over) {
        return;
    }
    if (e.key === 'ArrowUp') {
        result = move('up');
    } else if (e.key === 'ArrowDown') {
        result = move('down');
    } else if (e.key === 'ArrowLeft') {
        result = move('left');
    } else if (e.key === 'ArrowRight') {
        result = move('right');
    }
    if (result) {
        showUi();
        if (isWin()) {
            console.log('胜利');
            over = true;
        }
    }
}